import * as actions from '../actions/index';
import utils from 'utils';

// 对页面prop 数据进行管理
export const initialState = {
  projects: [],
  search: '',
  projectListLoaded: false,
  total: 0,
  currentPage: 1,
  order_by: 'last_activity_at',
  tbProjectName: '',
  repoCreatorIdentity: [],
};
const defaultAction = {
  type: 'doNothing',
};

export default function index(state = initialState, action = defaultAction) {
  switch (action.type) {
    case actions.UPDATE_DATA:
      return { ...state, ...action.data };
    case actions.RECEIVE_REPO_SETTING: {
      const repo_creator_identity = utils.getCompatibleSettingData(
        action.data.repo_creator_identity,
      );
      return {
        ...state,
        repoCreatorIdentity: repo_creator_identity,
      };
    }
    default:
      return state;
  }
}
